//
//  XFMainTabBar.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/10.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFMainTabBar.h"

@implementation XFMainTabBar

- (instancetype)init {
  self = [super init];
  if (self) {
    [self setupUI];
  }
  return self;
}

- (void)setupUI {

  [self addSubview:self.compBtn];
}

- (void)layoutSubviews {
  [super layoutSubviews];
  int index = 0;
  CGFloat w = self.bounds.size.width / 5;
  CGFloat h = self.bounds.size.height;
  CGRect rect = CGRectMake(0, 0, w, h);
  for (UIView *subview in self.subviews) {

    if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {

      subview.frame = CGRectOffset(rect, w * index, 0);

      index += (index == 1) ? 2 : 1;
    }
  }
  self.compBtn.frame = CGRectOffset(rect, w * 2, 0);
  //    [self bringSubviewToFront:_compBtn];
}

- (UIButton *)compBtn {

  if (_compBtn == nil) {
    UIButton *btn = [[UIButton alloc] init];

    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"]
                   forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage
                                imageNamed:@"tabbar_compose_button_highlighted"]
                   forState:UIControlStateSelected];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"]
         forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"]
         forState:UIControlStateSelected];
    _compBtn = btn;
  }
  return _compBtn;
}

@end
